// $ANTLR 3.1.2 D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g 2009-06-09 19:24:23

package org.protege.owl.examples.tab.grammar;


import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;import java.util.Stack;
import java.util.List;
import java.util.ArrayList;


public class FOLStage3 extends TreeParser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "DOT", "NOT", "FORALL", "SEPARATOR", "EXISTS", "RANGE_CLAUSE", "ID", "OR", "AND", "IS", "STAT", "QTF", "NEG", "EXPR", "VAR", "REL", "NEWLINE", "WS", "','", "':'", "';'"
    };
    public static final int STAT=14;
    public static final int T__24=24;
    public static final int T__23=23;
    public static final int T__22=22;
    public static final int QTF=15;
    public static final int FORALL=6;
    public static final int REL=19;
    public static final int SEPARATOR=7;
    public static final int NOT=5;
    public static final int ID=10;
    public static final int AND=12;
    public static final int EOF=-1;
    public static final int WS=21;
    public static final int EXPR=17;
    public static final int NEWLINE=20;
    public static final int RANGE_CLAUSE=9;
    public static final int IS=13;
    public static final int NEG=16;
    public static final int OR=11;
    public static final int VAR=18;
    public static final int EXISTS=8;
    public static final int DOT=4;

    // delegates
    // delegators


        public FOLStage3(TreeNodeStream input) {
            this(input, new RecognizerSharedState());
        }
        public FOLStage3(TreeNodeStream input, RecognizerSharedState state) {
            super(input, state);
             
        }
        
    protected TreeAdaptor adaptor = new CommonTreeAdaptor();

    public void setTreeAdaptor(TreeAdaptor adaptor) {
        this.adaptor = adaptor;
    }
    public TreeAdaptor getTreeAdaptor() {
        return adaptor;
    }

    public String[] getTokenNames() { return FOLStage3.tokenNames; }
    public String getGrammarFileName() { return "D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g"; }


    	boolean quantifierNeg = false;


    public static class stat_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "stat"
    // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:23:1: stat : ^( STAT qtflist expr[quantifierNeg] ) ;
    public final FOLStage3.stat_return stat() throws RecognitionException {
        FOLStage3.stat_return retval = new FOLStage3.stat_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        CommonTree STAT1=null;
        FOLStage3.qtflist_return qtflist2 = null;

        FOLStage3.expr_return expr3 = null;


        CommonTree STAT1_tree=null;

        try {
            // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:23:5: ( ^( STAT qtflist expr[quantifierNeg] ) )
            // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:24:2: ^( STAT qtflist expr[quantifierNeg] )
            {
            root_0 = (CommonTree)adaptor.nil();

            _last = (CommonTree)input.LT(1);
            {
            CommonTree _save_last_1 = _last;
            CommonTree _first_1 = null;
            CommonTree root_1 = (CommonTree)adaptor.nil();_last = (CommonTree)input.LT(1);
            STAT1=(CommonTree)match(input,STAT,FOLLOW_STAT_in_stat51); 
            STAT1_tree = (CommonTree)adaptor.dupNode(STAT1);

            root_1 = (CommonTree)adaptor.becomeRoot(STAT1_tree, root_1);



            match(input, Token.DOWN, null); 
            _last = (CommonTree)input.LT(1);
            pushFollow(FOLLOW_qtflist_in_stat53);
            qtflist2=qtflist();

            state._fsp--;

            adaptor.addChild(root_1, qtflist2.getTree());
            _last = (CommonTree)input.LT(1);
            pushFollow(FOLLOW_expr_in_stat55);
            expr3=expr(quantifierNeg);

            state._fsp--;

            adaptor.addChild(root_1, expr3.getTree());

            match(input, Token.UP, null); adaptor.addChild(root_0, root_1);_last = _save_last_1;
            }


            }

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "stat"

    public static class qtflist_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "qtflist"
    // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:27:1: qtflist : ^( QTF ( qtf )* ) ;
    public final FOLStage3.qtflist_return qtflist() throws RecognitionException {
        FOLStage3.qtflist_return retval = new FOLStage3.qtflist_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        CommonTree QTF4=null;
        FOLStage3.qtf_return qtf5 = null;


        CommonTree QTF4_tree=null;

        try {
            // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:27:8: ( ^( QTF ( qtf )* ) )
            // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:28:2: ^( QTF ( qtf )* )
            {
            root_0 = (CommonTree)adaptor.nil();

            _last = (CommonTree)input.LT(1);
            {
            CommonTree _save_last_1 = _last;
            CommonTree _first_1 = null;
            CommonTree root_1 = (CommonTree)adaptor.nil();_last = (CommonTree)input.LT(1);
            QTF4=(CommonTree)match(input,QTF,FOLLOW_QTF_in_qtflist69); 
            QTF4_tree = (CommonTree)adaptor.dupNode(QTF4);

            root_1 = (CommonTree)adaptor.becomeRoot(QTF4_tree, root_1);



            if ( input.LA(1)==Token.DOWN ) {
                match(input, Token.DOWN, null); 
                // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:28:8: ( qtf )*
                loop1:
                do {
                    int alt1=2;
                    int LA1_0 = input.LA(1);

                    if ( (LA1_0==FORALL||LA1_0==EXISTS||LA1_0==NEG) ) {
                        alt1=1;
                    }


                    switch (alt1) {
                	case 1 :
                	    // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:28:8: qtf
                	    {
                	    _last = (CommonTree)input.LT(1);
                	    pushFollow(FOLLOW_qtf_in_qtflist71);
                	    qtf5=qtf();

                	    state._fsp--;

                	    adaptor.addChild(root_1, qtf5.getTree());

                	    }
                	    break;

                	default :
                	    break loop1;
                    }
                } while (true);


                match(input, Token.UP, null); 
            }adaptor.addChild(root_0, root_1);_last = _save_last_1;
            }


            }

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "qtflist"

    public static class qtf_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "qtf"
    // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:31:1: qtf : ( ^( NEG qtfpart ) -> qtfpart | qtfpart );
    public final FOLStage3.qtf_return qtf() throws RecognitionException {
        FOLStage3.qtf_return retval = new FOLStage3.qtf_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        CommonTree NEG6=null;
        FOLStage3.qtfpart_return qtfpart7 = null;

        FOLStage3.qtfpart_return qtfpart8 = null;


        CommonTree NEG6_tree=null;
        RewriteRuleNodeStream stream_NEG=new RewriteRuleNodeStream(adaptor,"token NEG");
        RewriteRuleSubtreeStream stream_qtfpart=new RewriteRuleSubtreeStream(adaptor,"rule qtfpart");
        try {
            // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:31:4: ( ^( NEG qtfpart ) -> qtfpart | qtfpart )
            int alt2=2;
            int LA2_0 = input.LA(1);

            if ( (LA2_0==NEG) ) {
                alt2=1;
            }
            else if ( (LA2_0==FORALL||LA2_0==EXISTS) ) {
                alt2=2;
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 2, 0, input);

                throw nvae;
            }
            switch (alt2) {
                case 1 :
                    // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:32:2: ^( NEG qtfpart )
                    {
                    _last = (CommonTree)input.LT(1);
                    {
                    CommonTree _save_last_1 = _last;
                    CommonTree _first_1 = null;
                    CommonTree root_1 = (CommonTree)adaptor.nil();_last = (CommonTree)input.LT(1);
                    NEG6=(CommonTree)match(input,NEG,FOLLOW_NEG_in_qtf84);  
                    stream_NEG.add(NEG6);


                    quantifierNeg = !quantifierNeg;

                    match(input, Token.DOWN, null); 
                    _last = (CommonTree)input.LT(1);
                    pushFollow(FOLLOW_qtfpart_in_qtf88);
                    qtfpart7=qtfpart();

                    state._fsp--;

                    stream_qtfpart.add(qtfpart7.getTree());

                    match(input, Token.UP, null); adaptor.addChild(root_0, root_1);_last = _save_last_1;
                    }



                    // AST REWRITE
                    // elements: qtfpart
                    // token labels: 
                    // rule labels: retval
                    // token list labels: 
                    // rule list labels: 
                    // wildcard labels: 
                    retval.tree = root_0;
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

                    root_0 = (CommonTree)adaptor.nil();
                    // 33:2: -> qtfpart
                    {
                        adaptor.addChild(root_0, stream_qtfpart.nextTree());

                    }

                    retval.tree = root_0;
                    }
                    break;
                case 2 :
                    // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:35:2: qtfpart
                    {
                    root_0 = (CommonTree)adaptor.nil();

                    _last = (CommonTree)input.LT(1);
                    pushFollow(FOLLOW_qtfpart_in_qtf100);
                    qtfpart8=qtfpart();

                    state._fsp--;

                    adaptor.addChild(root_0, qtfpart8.getTree());

                    }
                    break;

            }
            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "qtf"

    public static class qtfpart_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "qtfpart"
    // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:38:1: qtfpart : ( forall | exists );
    public final FOLStage3.qtfpart_return qtfpart() throws RecognitionException {
        FOLStage3.qtfpart_return retval = new FOLStage3.qtfpart_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        FOLStage3.forall_return forall9 = null;

        FOLStage3.exists_return exists10 = null;



        try {
            // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:38:8: ( forall | exists )
            int alt3=2;
            int LA3_0 = input.LA(1);

            if ( (LA3_0==FORALL) ) {
                alt3=1;
            }
            else if ( (LA3_0==EXISTS) ) {
                alt3=2;
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 3, 0, input);

                throw nvae;
            }
            switch (alt3) {
                case 1 :
                    // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:39:2: forall
                    {
                    root_0 = (CommonTree)adaptor.nil();

                    _last = (CommonTree)input.LT(1);
                    pushFollow(FOLLOW_forall_in_qtfpart111);
                    forall9=forall();

                    state._fsp--;

                    adaptor.addChild(root_0, forall9.getTree());

                    }
                    break;
                case 2 :
                    // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:41:2: exists
                    {
                    root_0 = (CommonTree)adaptor.nil();

                    _last = (CommonTree)input.LT(1);
                    pushFollow(FOLLOW_exists_in_qtfpart117);
                    exists10=exists();

                    state._fsp--;

                    adaptor.addChild(root_0, exists10.getTree());

                    }
                    break;

            }
            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "qtfpart"

    public static class forall_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "forall"
    // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:44:1: forall : ^( FORALL rng ) -> {quantifierNeg}? ^( EXISTS rng ) -> ^( FORALL rng ) ;
    public final FOLStage3.forall_return forall() throws RecognitionException {
        FOLStage3.forall_return retval = new FOLStage3.forall_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        CommonTree FORALL11=null;
        FOLStage3.rng_return rng12 = null;


        CommonTree FORALL11_tree=null;
        RewriteRuleNodeStream stream_FORALL=new RewriteRuleNodeStream(adaptor,"token FORALL");
        RewriteRuleSubtreeStream stream_rng=new RewriteRuleSubtreeStream(adaptor,"rule rng");
        try {
            // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:44:7: ( ^( FORALL rng ) -> {quantifierNeg}? ^( EXISTS rng ) -> ^( FORALL rng ) )
            // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:45:2: ^( FORALL rng )
            {
            _last = (CommonTree)input.LT(1);
            {
            CommonTree _save_last_1 = _last;
            CommonTree _first_1 = null;
            CommonTree root_1 = (CommonTree)adaptor.nil();_last = (CommonTree)input.LT(1);
            FORALL11=(CommonTree)match(input,FORALL,FOLLOW_FORALL_in_forall128);  
            stream_FORALL.add(FORALL11);



            match(input, Token.DOWN, null); 
            _last = (CommonTree)input.LT(1);
            pushFollow(FOLLOW_rng_in_forall130);
            rng12=rng();

            state._fsp--;

            stream_rng.add(rng12.getTree());

            match(input, Token.UP, null); adaptor.addChild(root_0, root_1);_last = _save_last_1;
            }



            // AST REWRITE
            // elements: rng, rng, FORALL
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            root_0 = (CommonTree)adaptor.nil();
            // 46:2: -> {quantifierNeg}? ^( EXISTS rng )
            if (quantifierNeg) {
                // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:46:22: ^( EXISTS rng )
                {
                CommonTree root_1 = (CommonTree)adaptor.nil();
                root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(EXISTS, "EXISTS"), root_1);

                adaptor.addChild(root_1, stream_rng.nextTree());

                adaptor.addChild(root_0, root_1);
                }

            }
            else // 47:2: -> ^( FORALL rng )
            {
                // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:47:5: ^( FORALL rng )
                {
                CommonTree root_1 = (CommonTree)adaptor.nil();
                root_1 = (CommonTree)adaptor.becomeRoot(stream_FORALL.nextNode(), root_1);

                adaptor.addChild(root_1, stream_rng.nextTree());

                adaptor.addChild(root_0, root_1);
                }

            }

            retval.tree = root_0;
            }

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "forall"

    public static class exists_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "exists"
    // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:50:1: exists : ^( EXISTS rng ) -> {quantifierNeg}? ^( FORALL rng ) -> ^( EXISTS rng ) ;
    public final FOLStage3.exists_return exists() throws RecognitionException {
        FOLStage3.exists_return retval = new FOLStage3.exists_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        CommonTree EXISTS13=null;
        FOLStage3.rng_return rng14 = null;


        CommonTree EXISTS13_tree=null;
        RewriteRuleNodeStream stream_EXISTS=new RewriteRuleNodeStream(adaptor,"token EXISTS");
        RewriteRuleSubtreeStream stream_rng=new RewriteRuleSubtreeStream(adaptor,"rule rng");
        try {
            // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:50:7: ( ^( EXISTS rng ) -> {quantifierNeg}? ^( FORALL rng ) -> ^( EXISTS rng ) )
            // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:51:2: ^( EXISTS rng )
            {
            _last = (CommonTree)input.LT(1);
            {
            CommonTree _save_last_1 = _last;
            CommonTree _first_1 = null;
            CommonTree root_1 = (CommonTree)adaptor.nil();_last = (CommonTree)input.LT(1);
            EXISTS13=(CommonTree)match(input,EXISTS,FOLLOW_EXISTS_in_exists162);  
            stream_EXISTS.add(EXISTS13);



            match(input, Token.DOWN, null); 
            _last = (CommonTree)input.LT(1);
            pushFollow(FOLLOW_rng_in_exists164);
            rng14=rng();

            state._fsp--;

            stream_rng.add(rng14.getTree());

            match(input, Token.UP, null); adaptor.addChild(root_0, root_1);_last = _save_last_1;
            }



            // AST REWRITE
            // elements: rng, rng, EXISTS
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            root_0 = (CommonTree)adaptor.nil();
            // 52:2: -> {quantifierNeg}? ^( FORALL rng )
            if (quantifierNeg) {
                // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:52:22: ^( FORALL rng )
                {
                CommonTree root_1 = (CommonTree)adaptor.nil();
                root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(FORALL, "FORALL"), root_1);

                adaptor.addChild(root_1, stream_rng.nextTree());

                adaptor.addChild(root_0, root_1);
                }

            }
            else // 53:2: -> ^( EXISTS rng )
            {
                // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:53:5: ^( EXISTS rng )
                {
                CommonTree root_1 = (CommonTree)adaptor.nil();
                root_1 = (CommonTree)adaptor.becomeRoot(stream_EXISTS.nextNode(), root_1);

                adaptor.addChild(root_1, stream_rng.nextTree());

                adaptor.addChild(root_0, root_1);
                }

            }

            retval.tree = root_0;
            }

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "exists"

    public static class rng_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "rng"
    // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:56:1: rng : varlist ^( EXPR expr[false] ) ;
    public final FOLStage3.rng_return rng() throws RecognitionException {
        FOLStage3.rng_return retval = new FOLStage3.rng_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        CommonTree EXPR16=null;
        FOLStage3.varlist_return varlist15 = null;

        FOLStage3.expr_return expr17 = null;


        CommonTree EXPR16_tree=null;

        try {
            // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:56:4: ( varlist ^( EXPR expr[false] ) )
            // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:57:2: varlist ^( EXPR expr[false] )
            {
            root_0 = (CommonTree)adaptor.nil();

            _last = (CommonTree)input.LT(1);
            pushFollow(FOLLOW_varlist_in_rng195);
            varlist15=varlist();

            state._fsp--;

            adaptor.addChild(root_0, varlist15.getTree());
            _last = (CommonTree)input.LT(1);
            {
            CommonTree _save_last_1 = _last;
            CommonTree _first_1 = null;
            CommonTree root_1 = (CommonTree)adaptor.nil();_last = (CommonTree)input.LT(1);
            EXPR16=(CommonTree)match(input,EXPR,FOLLOW_EXPR_in_rng198); 
            EXPR16_tree = (CommonTree)adaptor.dupNode(EXPR16);

            root_1 = (CommonTree)adaptor.becomeRoot(EXPR16_tree, root_1);



            match(input, Token.DOWN, null); 
            _last = (CommonTree)input.LT(1);
            pushFollow(FOLLOW_expr_in_rng200);
            expr17=expr(false);

            state._fsp--;

            adaptor.addChild(root_1, expr17.getTree());

            match(input, Token.UP, null); adaptor.addChild(root_0, root_1);_last = _save_last_1;
            }


            }

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "rng"

    public static class varlist_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "varlist"
    // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:60:1: varlist : ^( VAR ( ID )+ ) ;
    public final FOLStage3.varlist_return varlist() throws RecognitionException {
        FOLStage3.varlist_return retval = new FOLStage3.varlist_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        CommonTree VAR18=null;
        CommonTree ID19=null;

        CommonTree VAR18_tree=null;
        CommonTree ID19_tree=null;

        try {
            // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:60:8: ( ^( VAR ( ID )+ ) )
            // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:61:2: ^( VAR ( ID )+ )
            {
            root_0 = (CommonTree)adaptor.nil();

            _last = (CommonTree)input.LT(1);
            {
            CommonTree _save_last_1 = _last;
            CommonTree _first_1 = null;
            CommonTree root_1 = (CommonTree)adaptor.nil();_last = (CommonTree)input.LT(1);
            VAR18=(CommonTree)match(input,VAR,FOLLOW_VAR_in_varlist213); 
            VAR18_tree = (CommonTree)adaptor.dupNode(VAR18);

            root_1 = (CommonTree)adaptor.becomeRoot(VAR18_tree, root_1);



            match(input, Token.DOWN, null); 
            // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:61:8: ( ID )+
            int cnt4=0;
            loop4:
            do {
                int alt4=2;
                int LA4_0 = input.LA(1);

                if ( (LA4_0==ID) ) {
                    alt4=1;
                }


                switch (alt4) {
            	case 1 :
            	    // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:61:8: ID
            	    {
            	    _last = (CommonTree)input.LT(1);
            	    ID19=(CommonTree)match(input,ID,FOLLOW_ID_in_varlist215); 
            	    ID19_tree = (CommonTree)adaptor.dupNode(ID19);

            	    adaptor.addChild(root_1, ID19_tree);


            	    }
            	    break;

            	default :
            	    if ( cnt4 >= 1 ) break loop4;
                        EarlyExitException eee =
                            new EarlyExitException(4, input);
                        throw eee;
                }
                cnt4++;
            } while (true);


            match(input, Token.UP, null); adaptor.addChild(root_0, root_1);_last = _save_last_1;
            }


            }

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "varlist"

    public static class expr_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "expr"
    // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:64:1: expr[boolean neg] : ( or[$neg] | and[$neg] | not[$neg] | quark[$neg] );
    public final FOLStage3.expr_return expr(boolean neg) throws RecognitionException {
        FOLStage3.expr_return retval = new FOLStage3.expr_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        FOLStage3.or_return or20 = null;

        FOLStage3.and_return and21 = null;

        FOLStage3.not_return not22 = null;

        FOLStage3.quark_return quark23 = null;



        try {
            // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:65:2: ( or[$neg] | and[$neg] | not[$neg] | quark[$neg] )
            int alt5=4;
            switch ( input.LA(1) ) {
            case OR:
                {
                alt5=1;
                }
                break;
            case AND:
                {
                alt5=2;
                }
                break;
            case NOT:
                {
                alt5=3;
                }
                break;
            case IS:
            case REL:
                {
                alt5=4;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("", 5, 0, input);

                throw nvae;
            }

            switch (alt5) {
                case 1 :
                    // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:66:2: or[$neg]
                    {
                    root_0 = (CommonTree)adaptor.nil();

                    _last = (CommonTree)input.LT(1);
                    pushFollow(FOLLOW_or_in_expr230);
                    or20=or(neg);

                    state._fsp--;

                    adaptor.addChild(root_0, or20.getTree());

                    }
                    break;
                case 2 :
                    // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:68:2: and[$neg]
                    {
                    root_0 = (CommonTree)adaptor.nil();

                    _last = (CommonTree)input.LT(1);
                    pushFollow(FOLLOW_and_in_expr237);
                    and21=and(neg);

                    state._fsp--;

                    adaptor.addChild(root_0, and21.getTree());

                    }
                    break;
                case 3 :
                    // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:70:2: not[$neg]
                    {
                    root_0 = (CommonTree)adaptor.nil();

                    _last = (CommonTree)input.LT(1);
                    pushFollow(FOLLOW_not_in_expr244);
                    not22=not(neg);

                    state._fsp--;

                    adaptor.addChild(root_0, not22.getTree());

                    }
                    break;
                case 4 :
                    // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:72:2: quark[$neg]
                    {
                    root_0 = (CommonTree)adaptor.nil();

                    _last = (CommonTree)input.LT(1);
                    pushFollow(FOLLOW_quark_in_expr251);
                    quark23=quark(neg);

                    state._fsp--;

                    adaptor.addChild(root_0, quark23.getTree());

                    }
                    break;

            }
            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "expr"

    public static class or_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "or"
    // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:75:1: or[boolean neg] : ^( OR expr[$neg] expr[$neg] ) -> {$neg}? ^( AND expr expr ) -> ^( OR expr expr ) ;
    public final FOLStage3.or_return or(boolean neg) throws RecognitionException {
        FOLStage3.or_return retval = new FOLStage3.or_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        CommonTree OR24=null;
        FOLStage3.expr_return expr25 = null;

        FOLStage3.expr_return expr26 = null;


        CommonTree OR24_tree=null;
        RewriteRuleNodeStream stream_OR=new RewriteRuleNodeStream(adaptor,"token OR");
        RewriteRuleSubtreeStream stream_expr=new RewriteRuleSubtreeStream(adaptor,"rule expr");
        try {
            // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:76:2: ( ^( OR expr[$neg] expr[$neg] ) -> {$neg}? ^( AND expr expr ) -> ^( OR expr expr ) )
            // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:77:2: ^( OR expr[$neg] expr[$neg] )
            {
            _last = (CommonTree)input.LT(1);
            {
            CommonTree _save_last_1 = _last;
            CommonTree _first_1 = null;
            CommonTree root_1 = (CommonTree)adaptor.nil();_last = (CommonTree)input.LT(1);
            OR24=(CommonTree)match(input,OR,FOLLOW_OR_in_or267);  
            stream_OR.add(OR24);



            match(input, Token.DOWN, null); 
            _last = (CommonTree)input.LT(1);
            pushFollow(FOLLOW_expr_in_or269);
            expr25=expr(neg);

            state._fsp--;

            stream_expr.add(expr25.getTree());
            _last = (CommonTree)input.LT(1);
            pushFollow(FOLLOW_expr_in_or272);
            expr26=expr(neg);

            state._fsp--;

            stream_expr.add(expr26.getTree());

            match(input, Token.UP, null); adaptor.addChild(root_0, root_1);_last = _save_last_1;
            }



            // AST REWRITE
            // elements: expr, OR, expr, expr, expr
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            root_0 = (CommonTree)adaptor.nil();
            // 78:2: -> {$neg}? ^( AND expr expr )
            if (neg) {
                // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:78:13: ^( AND expr expr )
                {
                CommonTree root_1 = (CommonTree)adaptor.nil();
                root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(AND, "AND"), root_1);

                adaptor.addChild(root_1, stream_expr.nextTree());
                adaptor.addChild(root_1, stream_expr.nextTree());

                adaptor.addChild(root_0, root_1);
                }

            }
            else // 79:2: -> ^( OR expr expr )
            {
                // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:79:5: ^( OR expr expr )
                {
                CommonTree root_1 = (CommonTree)adaptor.nil();
                root_1 = (CommonTree)adaptor.becomeRoot(stream_OR.nextNode(), root_1);

                adaptor.addChild(root_1, stream_expr.nextTree());
                adaptor.addChild(root_1, stream_expr.nextTree());

                adaptor.addChild(root_0, root_1);
                }

            }

            retval.tree = root_0;
            }

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "or"

    public static class and_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "and"
    // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:81:1: and[boolean neg] : ^( AND expr[$neg] expr[$neg] ) -> {$neg}? ^( OR expr expr ) -> ^( AND expr expr ) ;
    public final FOLStage3.and_return and(boolean neg) throws RecognitionException {
        FOLStage3.and_return retval = new FOLStage3.and_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        CommonTree AND27=null;
        FOLStage3.expr_return expr28 = null;

        FOLStage3.expr_return expr29 = null;


        CommonTree AND27_tree=null;
        RewriteRuleNodeStream stream_AND=new RewriteRuleNodeStream(adaptor,"token AND");
        RewriteRuleSubtreeStream stream_expr=new RewriteRuleSubtreeStream(adaptor,"rule expr");
        try {
            // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:82:2: ( ^( AND expr[$neg] expr[$neg] ) -> {$neg}? ^( OR expr expr ) -> ^( AND expr expr ) )
            // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:83:2: ^( AND expr[$neg] expr[$neg] )
            {
            _last = (CommonTree)input.LT(1);
            {
            CommonTree _save_last_1 = _last;
            CommonTree _first_1 = null;
            CommonTree root_1 = (CommonTree)adaptor.nil();_last = (CommonTree)input.LT(1);
            AND27=(CommonTree)match(input,AND,FOLLOW_AND_in_and311);  
            stream_AND.add(AND27);



            match(input, Token.DOWN, null); 
            _last = (CommonTree)input.LT(1);
            pushFollow(FOLLOW_expr_in_and313);
            expr28=expr(neg);

            state._fsp--;

            stream_expr.add(expr28.getTree());
            _last = (CommonTree)input.LT(1);
            pushFollow(FOLLOW_expr_in_and316);
            expr29=expr(neg);

            state._fsp--;

            stream_expr.add(expr29.getTree());

            match(input, Token.UP, null); adaptor.addChild(root_0, root_1);_last = _save_last_1;
            }



            // AST REWRITE
            // elements: expr, expr, expr, expr, AND
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            root_0 = (CommonTree)adaptor.nil();
            // 84:2: -> {$neg}? ^( OR expr expr )
            if (neg) {
                // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:84:13: ^( OR expr expr )
                {
                CommonTree root_1 = (CommonTree)adaptor.nil();
                root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(OR, "OR"), root_1);

                adaptor.addChild(root_1, stream_expr.nextTree());
                adaptor.addChild(root_1, stream_expr.nextTree());

                adaptor.addChild(root_0, root_1);
                }

            }
            else // 85:2: -> ^( AND expr expr )
            {
                // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:85:5: ^( AND expr expr )
                {
                CommonTree root_1 = (CommonTree)adaptor.nil();
                root_1 = (CommonTree)adaptor.becomeRoot(stream_AND.nextNode(), root_1);

                adaptor.addChild(root_1, stream_expr.nextTree());
                adaptor.addChild(root_1, stream_expr.nextTree());

                adaptor.addChild(root_0, root_1);
                }

            }

            retval.tree = root_0;
            }

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "and"

    public static class not_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "not"
    // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:88:1: not[boolean neg] : ^( NOT expr[!$neg] ) -> expr ;
    public final FOLStage3.not_return not(boolean neg) throws RecognitionException {
        FOLStage3.not_return retval = new FOLStage3.not_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        CommonTree NOT30=null;
        FOLStage3.expr_return expr31 = null;


        CommonTree NOT30_tree=null;
        RewriteRuleNodeStream stream_NOT=new RewriteRuleNodeStream(adaptor,"token NOT");
        RewriteRuleSubtreeStream stream_expr=new RewriteRuleSubtreeStream(adaptor,"rule expr");
        try {
            // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:89:2: ( ^( NOT expr[!$neg] ) -> expr )
            // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:90:2: ^( NOT expr[!$neg] )
            {
            _last = (CommonTree)input.LT(1);
            {
            CommonTree _save_last_1 = _last;
            CommonTree _first_1 = null;
            CommonTree root_1 = (CommonTree)adaptor.nil();_last = (CommonTree)input.LT(1);
            NOT30=(CommonTree)match(input,NOT,FOLLOW_NOT_in_not356);  
            stream_NOT.add(NOT30);



            match(input, Token.DOWN, null); 
            _last = (CommonTree)input.LT(1);
            pushFollow(FOLLOW_expr_in_not358);
            expr31=expr(!neg);

            state._fsp--;

            stream_expr.add(expr31.getTree());

            match(input, Token.UP, null); adaptor.addChild(root_0, root_1);_last = _save_last_1;
            }



            // AST REWRITE
            // elements: expr
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            root_0 = (CommonTree)adaptor.nil();
            // 91:2: -> expr
            {
                adaptor.addChild(root_0, stream_expr.nextTree());

            }

            retval.tree = root_0;
            }

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "not"

    public static class quark_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "quark"
    // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:94:1: quark[boolean neg] : predcall -> {$neg}? ^( NOT predcall ) -> predcall ;
    public final FOLStage3.quark_return quark(boolean neg) throws RecognitionException {
        FOLStage3.quark_return retval = new FOLStage3.quark_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        FOLStage3.predcall_return predcall32 = null;


        RewriteRuleSubtreeStream stream_predcall=new RewriteRuleSubtreeStream(adaptor,"rule predcall");
        try {
            // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:95:2: ( predcall -> {$neg}? ^( NOT predcall ) -> predcall )
            // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:96:2: predcall
            {
            _last = (CommonTree)input.LT(1);
            pushFollow(FOLLOW_predcall_in_quark378);
            predcall32=predcall();

            state._fsp--;

            stream_predcall.add(predcall32.getTree());


            // AST REWRITE
            // elements: predcall, predcall
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            root_0 = (CommonTree)adaptor.nil();
            // 97:2: -> {$neg}? ^( NOT predcall )
            if (neg) {
                // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:97:13: ^( NOT predcall )
                {
                CommonTree root_1 = (CommonTree)adaptor.nil();
                root_1 = (CommonTree)adaptor.becomeRoot((CommonTree)adaptor.create(NOT, "NOT"), root_1);

                adaptor.addChild(root_1, stream_predcall.nextTree());

                adaptor.addChild(root_0, root_1);
                }

            }
            else // 98:2: -> predcall
            {
                adaptor.addChild(root_0, stream_predcall.nextTree());

            }

            retval.tree = root_0;
            }

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "quark"

    public static class predcall_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "predcall"
    // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:101:1: predcall : ( ^( IS ID arg ) | ^( REL ID arg arg ) );
    public final FOLStage3.predcall_return predcall() throws RecognitionException {
        FOLStage3.predcall_return retval = new FOLStage3.predcall_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        CommonTree IS33=null;
        CommonTree ID34=null;
        CommonTree REL36=null;
        CommonTree ID37=null;
        FOLStage3.arg_return arg35 = null;

        FOLStage3.arg_return arg38 = null;

        FOLStage3.arg_return arg39 = null;


        CommonTree IS33_tree=null;
        CommonTree ID34_tree=null;
        CommonTree REL36_tree=null;
        CommonTree ID37_tree=null;

        try {
            // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:101:9: ( ^( IS ID arg ) | ^( REL ID arg arg ) )
            int alt6=2;
            int LA6_0 = input.LA(1);

            if ( (LA6_0==IS) ) {
                alt6=1;
            }
            else if ( (LA6_0==REL) ) {
                alt6=2;
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 6, 0, input);

                throw nvae;
            }
            switch (alt6) {
                case 1 :
                    // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:102:2: ^( IS ID arg )
                    {
                    root_0 = (CommonTree)adaptor.nil();

                    _last = (CommonTree)input.LT(1);
                    {
                    CommonTree _save_last_1 = _last;
                    CommonTree _first_1 = null;
                    CommonTree root_1 = (CommonTree)adaptor.nil();_last = (CommonTree)input.LT(1);
                    IS33=(CommonTree)match(input,IS,FOLLOW_IS_in_predcall405); 
                    IS33_tree = (CommonTree)adaptor.dupNode(IS33);

                    root_1 = (CommonTree)adaptor.becomeRoot(IS33_tree, root_1);



                    match(input, Token.DOWN, null); 
                    _last = (CommonTree)input.LT(1);
                    ID34=(CommonTree)match(input,ID,FOLLOW_ID_in_predcall407); 
                    ID34_tree = (CommonTree)adaptor.dupNode(ID34);

                    adaptor.addChild(root_1, ID34_tree);

                    _last = (CommonTree)input.LT(1);
                    pushFollow(FOLLOW_arg_in_predcall409);
                    arg35=arg();

                    state._fsp--;

                    adaptor.addChild(root_1, arg35.getTree());

                    match(input, Token.UP, null); adaptor.addChild(root_0, root_1);_last = _save_last_1;
                    }


                    }
                    break;
                case 2 :
                    // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:104:2: ^( REL ID arg arg )
                    {
                    root_0 = (CommonTree)adaptor.nil();

                    _last = (CommonTree)input.LT(1);
                    {
                    CommonTree _save_last_1 = _last;
                    CommonTree _first_1 = null;
                    CommonTree root_1 = (CommonTree)adaptor.nil();_last = (CommonTree)input.LT(1);
                    REL36=(CommonTree)match(input,REL,FOLLOW_REL_in_predcall417); 
                    REL36_tree = (CommonTree)adaptor.dupNode(REL36);

                    root_1 = (CommonTree)adaptor.becomeRoot(REL36_tree, root_1);



                    match(input, Token.DOWN, null); 
                    _last = (CommonTree)input.LT(1);
                    ID37=(CommonTree)match(input,ID,FOLLOW_ID_in_predcall419); 
                    ID37_tree = (CommonTree)adaptor.dupNode(ID37);

                    adaptor.addChild(root_1, ID37_tree);

                    _last = (CommonTree)input.LT(1);
                    pushFollow(FOLLOW_arg_in_predcall421);
                    arg38=arg();

                    state._fsp--;

                    adaptor.addChild(root_1, arg38.getTree());
                    _last = (CommonTree)input.LT(1);
                    pushFollow(FOLLOW_arg_in_predcall423);
                    arg39=arg();

                    state._fsp--;

                    adaptor.addChild(root_1, arg39.getTree());

                    match(input, Token.UP, null); adaptor.addChild(root_0, root_1);_last = _save_last_1;
                    }


                    }
                    break;

            }
            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "predcall"

    public static class arg_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "arg"
    // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:107:1: arg : ID ;
    public final FOLStage3.arg_return arg() throws RecognitionException {
        FOLStage3.arg_return retval = new FOLStage3.arg_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        CommonTree ID40=null;

        CommonTree ID40_tree=null;

        try {
            // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:107:4: ( ID )
            // D:\\Projekty\\Protege4Workspace\\org.protege.editor.owl.examples.tab\\src\\org\\protege\\owl\\examples\\tab\\grammar\\FOLStage3.g:108:2: ID
            {
            root_0 = (CommonTree)adaptor.nil();

            _last = (CommonTree)input.LT(1);
            ID40=(CommonTree)match(input,ID,FOLLOW_ID_in_arg434); 
            ID40_tree = (CommonTree)adaptor.dupNode(ID40);

            adaptor.addChild(root_0, ID40_tree);


            }

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "arg"

    // Delegated rules


 

    public static final BitSet FOLLOW_STAT_in_stat51 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_qtflist_in_stat53 = new BitSet(new long[]{0x0000000000083820L});
    public static final BitSet FOLLOW_expr_in_stat55 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_QTF_in_qtflist69 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_qtf_in_qtflist71 = new BitSet(new long[]{0x0000000000010148L});
    public static final BitSet FOLLOW_NEG_in_qtf84 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_qtfpart_in_qtf88 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_qtfpart_in_qtf100 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_forall_in_qtfpart111 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_exists_in_qtfpart117 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_FORALL_in_forall128 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_rng_in_forall130 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_EXISTS_in_exists162 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_rng_in_exists164 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_varlist_in_rng195 = new BitSet(new long[]{0x0000000000020000L});
    public static final BitSet FOLLOW_EXPR_in_rng198 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expr_in_rng200 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_VAR_in_varlist213 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_ID_in_varlist215 = new BitSet(new long[]{0x0000000000000408L});
    public static final BitSet FOLLOW_or_in_expr230 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_and_in_expr237 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_not_in_expr244 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_quark_in_expr251 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_OR_in_or267 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expr_in_or269 = new BitSet(new long[]{0x0000000000083820L});
    public static final BitSet FOLLOW_expr_in_or272 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_AND_in_and311 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expr_in_and313 = new BitSet(new long[]{0x0000000000083820L});
    public static final BitSet FOLLOW_expr_in_and316 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_NOT_in_not356 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_expr_in_not358 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_predcall_in_quark378 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_IS_in_predcall405 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_ID_in_predcall407 = new BitSet(new long[]{0x0000000000000400L});
    public static final BitSet FOLLOW_arg_in_predcall409 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_REL_in_predcall417 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_ID_in_predcall419 = new BitSet(new long[]{0x0000000000000400L});
    public static final BitSet FOLLOW_arg_in_predcall421 = new BitSet(new long[]{0x0000000000000400L});
    public static final BitSet FOLLOW_arg_in_predcall423 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_ID_in_arg434 = new BitSet(new long[]{0x0000000000000002L});

}